package com.acmedcare.framework.exchange.center.core;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class StreamReaderUtil {

  /**
   * @param stream sub process
   */
  public static void readToFile(InputStream stream) {

    BufferedReader br = null;
    try {
      br = new BufferedReader(new InputStreamReader(stream));
      String line = null;
      while ((line = br.readLine()) != null) {
        log.info(line);
      }
    } catch (Exception e) {
      log.error("读取wget下载流异常", e);
    } finally {
      try {
        //释放资源
        stream.close();
        if (br != null) {
          br.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
}
